// 自定义消息类型
export interface CustomMessage {
  id: string;
  type: 'human' | 'ai' | 'tool' | 'system';
  content: Array<{ type: string; text?: string; [key: string]: any }> | string;
  role?: 'user' | 'assistant' | 'system';
  timestamp?: string;
  tool_calls?: any[];
  [key: string]: any;
}

// 自定义Checkpoint类型
export interface CustomCheckpoint {
  thread_id: string;
  checkpoint_ns?: string;
  checkpoint_id?: string;
  checkpoint_map?: Record<string, any>;
}

// 自定义Thread类型
export interface CustomThread {
  thread_id: string;
  created_at: string;
  updated_at: string;
  metadata?: Record<string, any>;
  values?: Record<string, any>;
}

// 自定义中断类型
export interface CustomInterrupt {
  id: string;
  action_request: {
    action: string;
    [key: string]: any;
  };
  value?: any;
  config?: {
    allow_accept?: boolean;
    allow_ignore?: boolean;
    allow_respond?: boolean;
    allow_edit?: boolean;
    [key: string]: any;
  };
}

// 自定义响应类型
export interface CustomResponse {
  id: string;
  response: string;
  [key: string]: any;
}

// HumanResponse相关类型
export interface HumanResponse {
  type: string;
  args?: any;
  [key: string]: any;
}

export type HumanResponseWithEdits = CustomResponse &
  (
    | { acceptAllowed?: false; editsMade?: never }
    | { acceptAllowed?: true; editsMade?: boolean }
  );

export type Email = {
  id: string;
  thread_id: string;
  from_email: string;
  to_email: string;
  subject: string;
  page_content: string;
  send_time: string | undefined;
  read?: boolean;
  status?: "in-queue" | "processing" | "hitl" | "done";
};

export interface ThreadValues {
  email: Email;
  messages: CustomMessage[];
  triage: {
    logic: string;
    response: string;
  };
}

export type ThreadData<
  ThreadValues extends Record<string, any> = Record<string, any>,
> = {
  thread: CustomThread;
} & (
  | {
      status: "interrupted";
      interrupts: CustomInterrupt[] | undefined;
    }
  | {
      status: "idle" | "busy" | "error";
      interrupts?: never;
    }
);

export type ThreadStatusWithAll = "idle" | "busy" | "error" | "interrupted" | "all";

export type SubmitType = "accept" | "response" | "edit";

export interface AgentInbox {
  /**
   * A unique identifier for the inbox.
   */
  id: string;
  /**
   * The ID of the graph.
   */
  graphId: string;
  /**
   * The URL of the deployment. Either a localhost URL, or a deployment URL.
   */
  deploymentUrl: string;
  /**
   * Optional name for the inbox, used in the UI to label the inbox.
   */
  name?: string;
  /**
   * Whether or not the inbox is selected.
   */
  selected: boolean;
}
